package com.tangcco.lockwell.service.impl;


import cn.hutool.json.JSONUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tangcco.lockwell.domain.*;
import com.tangcco.lockwell.domain.question.QuestionItemObject;
import com.tangcco.lockwell.domain.question.QuestionObject;
import com.tangcco.lockwell.repository.DataDictionaryMapper;
import com.tangcco.lockwell.repository.ExamPaperMapper;
import com.tangcco.lockwell.repository.QuestionMapper;
import com.tangcco.lockwell.service.*;
import com.tangcco.lockwell.service.enums.ActionEnum;
import com.tangcco.lockwell.service.enums.ExamPaperTypeEnum;
import com.tangcco.lockwell.service.exam.ExamPaperQuestionItemObject;
import com.tangcco.lockwell.service.exam.ExamPaperTitleItemObject;
import com.tangcco.lockwell.utility.*;
import com.tangcco.lockwell.viewmodel.admin.exam.*;
import com.tangcco.lockwell.viewmodel.admin.question.*;
import com.tangcco.lockwell.viewmodel.student.dashboard.PaperFilter;
import com.tangcco.lockwell.viewmodel.student.dashboard.PaperInfo;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@Service
public class ExamPaperServiceImpl extends BaseServiceImpl<ExamPaper> implements ExamPaperService {
    Integer index;
    protected final static ModelMapper modelMapper = ModelMapperSingle.Instance();
    private final ExamPaperMapper examPaperMapper;
    private final QuestionMapper questionMapper;
    private final TextContentService textContentService;
    private final QuestionService questionService;
    private final SubjectService subjectService;
    private final DataDictionaryMapper dataDictionaryMapper;
    private final ArticleService articleService;
    @Autowired
    public ExamPaperServiceImpl(ExamPaperMapper examPaperMapper, QuestionMapper questionMapper, TextContentService textContentService, QuestionService questionService, SubjectService subjectService, DataDictionaryMapper dataDictionaryMapper,ArticleService articleService) {
        super(examPaperMapper);
        this.examPaperMapper = examPaperMapper;
        this.questionMapper = questionMapper;
        this.textContentService = textContentService;
        this.questionService = questionService;
        this.subjectService = subjectService;
        this.dataDictionaryMapper = dataDictionaryMapper;
        this.articleService = articleService;
    }

    @Override
    public ExamPaper savePaperFromVM(ExamPaperEditRequestVM examPaperEditRequestVM, User user) {
        ExamPaper examPaper;
        index = 0;
        Integer score = 0;
        ActionEnum actionEnum = (examPaperEditRequestVM.getPaperId() == null) ? ActionEnum.ADD : ActionEnum.UPDATE;
        Date now = new Date();
        List<ExamPaperTitleItemVM> titleItemsVM1 = examPaperEditRequestVM.getTitleItems();
        List<ExamPaperTitleItemObject> examPaperTitleItemObjects = new ArrayList<>();
        List<ExamPaperTitleItemVM> titleItemsVM = new ArrayList<>();
        for (ExamPaperTitleItemVM titleItemVM : titleItemsVM1) {
            ExamPaperTitleItemVM titleItemVM1 = new ExamPaperTitleItemVM();
            titleItemVM1.setName(titleItemVM.getName());
            List<QuestionEditRequestVM> questionItems = new ArrayList<>();
            ExamPaperTitleItemObject examPaperTitleItemObject = new ExamPaperTitleItemObject();
            examPaperTitleItemObject.setName(titleItemVM.getName());
            List<ExamPaperQuestionItemObject> questionTitleItemObjectList = new ArrayList<>();
            for (QuestionEditRequestVM questionEditRequestVM : titleItemVM.getQuestionItems()) {

                if (questionEditRequestVM.getScore()!= null) {
                    String score1 = questionEditRequestVM.getScore();
                    Integer s=0;
                    for (int i = 0; i < score1.length(); i++) {
                        char c = score1.charAt(i);
                        if (Character.isDigit(c)) {
                            s = s*10+Character.getNumericValue(c);
                        }
                    }
                    score+=s;
                }
                ExamPaperQuestionItemObject examPaperQuestionItemObject = new ExamPaperQuestionItemObject(questionEditRequestVM.getId(),++index);
                questionTitleItemObjectList.add(examPaperQuestionItemObject);
                questionItems.add(questionEditRequestVM);


                titleItemVM1.setQuestionItems(questionItems);

            }
            titleItemsVM.add(titleItemVM1);
            examPaperTitleItemObject.setQuestionItems(questionTitleItemObjectList);
            examPaperTitleItemObjects.add(examPaperTitleItemObject);
        }
//        List<ExamPaperTitleItemObject> frameTextContentList = frameTextContentFromVM(titleItemsVM);
        String frameTextContentStr = JsonUtil.toJsonStr(examPaperTitleItemObjects);
        DataDictionary dataDictionary = dataDictionaryMapper.selectByPrimaryKey(examPaperEditRequestVM.getSubjectId());
        Integer subjectParentId = dataDictionary.getParentId();
        if (actionEnum == ActionEnum.ADD) {
            examPaper = modelMapper.map(examPaperEditRequestVM, ExamPaper.class);
            examPaper.setSubjectParentId(subjectParentId);
            TextContent frameTextContent = new TextContent(null,frameTextContentStr, DateToString.dateToString(now),null);
            textContentService.insertByFilter(frameTextContent);
            examPaper.setScore(score);
            examPaper.setFrameTextContentId(frameTextContent.getId());
            examPaper.setCreateTime(DateToString.dateToString(now));
            examPaper.setCreateUser(user.getUserId());
            examPaper.setDeleted(false);
            examPaperFromVM(examPaperEditRequestVM, examPaper, titleItemsVM);
            examPaperMapper.insertSelective(examPaper);
        }else {
            examPaper = examPaperMapper.selectByPrimaryKey(examPaperEditRequestVM.getPaperId());
            TextContent frameTextContent = textContentService.selectById(examPaper.getFrameTextContentId());
            frameTextContent.setContent(frameTextContentStr);
            frameTextContent.setModifyTime(DateToString.dateToString(now));
            textContentService.updateByIdFilter(frameTextContent);
            modelMapper.map(examPaperEditRequestVM, examPaper);

            examPaperFromVM(examPaperEditRequestVM, examPaper, titleItemsVM);
            examPaper.setModifyTime(DateToString.dateToString(now));
            examPaper.setSubjectParentId(subjectParentId);
            examPaper.setScore(score);
            examPaperMapper.updateByPrimaryKey(examPaper);
        }
        return examPaper;
    }

    @Override
    public EPaperEditRequestVM examPaperToVM(Integer id) throws ParseException {
        index = 0;
        ExamPaper examPaper = examPaperMapper.selectByPrimaryKey(id);
        ExamPaperEditRequestVM vm = modelMapper.map(examPaper, ExamPaperEditRequestVM.class);
        vm.setLevel(examPaper.getGradeLevel());
        TextContent frameTextContent = textContentService.selectById(examPaper.getFrameTextContentId());
        List<ExamPaperTitleItemObject> examPaperTitleItemObjects = JsonUtil.toJsonListObject(frameTextContent.getContent(), ExamPaperTitleItemObject.class);
        List<Integer> questionIds = Optional.ofNullable(examPaperTitleItemObjects)
                .orElse(Collections.emptyList()).stream()
                .filter(t -> t.getQuestionItems() != null)
                .flatMap(t -> t.getQuestionItems().stream()
                        .map(q -> q.getId()))
                .collect(Collectors.toList());
        List<Question> questions = questionMapper.selectByIds(questionIds);
        List<ExamPaperTitleItemVM> examPaperTitleItemVMS = examPaperTitleItemObjects.stream().map(t -> {
//            System.out.println("Processing ExamPaperTitleItem: " + t);
            ExamPaperTitleItemVM tTitleVM = modelMapper.map(t, ExamPaperTitleItemVM.class);
            List<QuestionEditRequestVM> questionItemsVM = t.getQuestionItems() != null ? t.getQuestionItems().stream().map(i -> {
//                System.out.println("Processing QuestionItem: " + i);
                Question question = questions.stream().filter(q -> q.getId().equals(i.getId())).findFirst().orElse(null);
                if (question != null) {
                    System.out.println("Question found: " + question);
                    QuestionEditRequestVM questionEditRequestVM = getQuestionEditRequestVM(question);
                    questionEditRequestVM.setItemOrder(i.getItemOrder());
                    return questionEditRequestVM;
                } else {
                    System.out.println("Question not found for id: " + i.getId());
                    return null;
                }
            }).filter(Objects::nonNull).collect(Collectors.toList()) : Collections.emptyList();
            tTitleVM.setQuestionItems(questionItemsVM);
            return tTitleVM;
        }).collect(Collectors.toList());
        vm.setTitleItems(examPaperTitleItemVMS);
        vm.setScore(ExamUtil.scoreToVM(examPaper.getScore()));
        if (ExamPaperTypeEnum.TimeLimit == ExamPaperTypeEnum.fromCode(examPaper.getPaperType())) {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            List<String> limitDateTime = Arrays.asList(DateTimeUtil.dateFormat(formatter.parse(examPaper.getLimitStartTime())), DateTimeUtil.dateFormat(formatter.parse(examPaper.getLimitEndTime())));
            vm.setLimitDateTime(limitDateTime);
        }
        EPaperEditRequestVM v = modelMapper.map(vm, EPaperEditRequestVM.class);
        DataDictionary d1 = dataDictionaryMapper.selectByPrimaryKey(examPaper.getPaperType());
        v.setPaperType(d1.getCategoryName());
        DataDictionary d2 = dataDictionaryMapper.selectByPrimaryKey(examPaper.getSubjectId());
        v.setSubject(d2.getCategoryName());
        v.setSubjectId(examPaper.getSubjectId());
        v.setPaperTypeId(examPaper.getPaperType());
        vm.setLevel(examPaper.getGradeLevel());
        return v;
    }

    @Override
    public PageInfo<ExamPaper> page(ExamPaperPageRequestVM requestVM) {
//        return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), "id desc").doSelectPageInfo(() ->
//                examPaperMapper.page(requestVM));
        PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize());
        List<ExamPaper> examPapers = examPaperMapper.page(requestVM);
        PageInfo<ExamPaper> pageInfo = new PageInfo<>(examPapers);
        return pageInfo;
    }

    @Override
    public List<PaperInfo> indexPaper(PaperFilter paperFilter) {
        return examPaperMapper.indexPaper(paperFilter);
    }


    @Override
    public Integer selectAllCount() {
        return examPaperMapper.selectAllCount();
    }

    private void examPaperFromVM(ExamPaperEditRequestVM examPaperEditRequestVM, ExamPaper examPaper, List<ExamPaperTitleItemVM> titleItemsVM) {
        Integer questionCount = titleItemsVM.stream()
                .mapToInt(t -> t.getQuestionItems().size()).sum();
        Integer score = titleItemsVM.stream()
                .flatMapToInt(t -> t.getQuestionItems().stream()
                        .filter(Objects::nonNull)  // 过滤掉 null 对象
                        .mapToInt(q -> {
                            Integer scoreValue = ExamUtil.scoreFromVM(q.getScore());
                            return scoreValue != null ? scoreValue : 0;  // 处理 null 值
                        })
                ).sum();
        examPaper.setQuestionCount(questionCount);
        examPaper.setScore(score);
        examPaper.setGradeLevel(examPaperEditRequestVM.getLevel());
        List<String> dateTimes = examPaperEditRequestVM.getLimitDateTime();
        if (ExamPaperTypeEnum.TimeLimit == ExamPaperTypeEnum.fromCode(examPaper.getPaperType())) {
            examPaper.setLimitStartTime(DateToString.dateToString(DateTimeUtil.parse(dateTimes.get(0), DateTimeUtil.STANDER_FORMAT)));
            examPaper.setLimitEndTime(DateToString.dateToString(DateTimeUtil.parse(dateTimes.get(1), DateTimeUtil.STANDER_FORMAT)));
        }
    }

    private List<ExamPaperTitleItemObject> frameTextContentFromVM(List<ExamPaperTitleItemVM> titleItems) {
        AtomicInteger index = new AtomicInteger(1);
        return titleItems.stream().map(t -> {
            ExamPaperTitleItemObject titleItem = modelMapper.map(t, ExamPaperTitleItemObject.class);
            List<ExamPaperQuestionItemObject> questionItems = t.getQuestionItems().stream()
                    .map(q -> {
                        ExamPaperQuestionItemObject examPaperQuestionItemObject = modelMapper.map(q, ExamPaperQuestionItemObject.class);
                        examPaperQuestionItemObject.setItemOrder(index.getAndIncrement());
                        return examPaperQuestionItemObject;
                    })
                    .collect(Collectors.toList());
            titleItem.setQuestionItems(questionItems);
            return titleItem;
        }).collect(Collectors.toList());
    }
    @Override
    public QuestionEditRequestVM getQuestionEditRequestVM(Question question) {
        //题目映射
        List<QuestionMySqlVm> questionMySqlVms = JsonUtil.toJsonListObject(question.getTextContent(),QuestionMySqlVm.class);
        if(question.getSubjectParentId()==2){
            List<QuestionIndex> questionIndexList = new ArrayList<>();
            QuestionMySqlVm questionMySqlVm =(QuestionMySqlVm) questionMySqlVms.get(0);
            List<QuestionMySqlSelectVm> questionItems = questionMySqlVm.getItem();
            List<QuestionItemObject> questionItemObjects = new ArrayList<>();
            if(questionMySqlVm.getItem() != null){
                for (QuestionMySqlSelectVm questionMySqlSelectVm : questionItems) {
                    QuestionItemObject questionItemObject = modelMapper.map(questionMySqlSelectVm, QuestionItemObject.class);
                    questionItemObjects.add(questionItemObject);
                }
            }

            QuestionObject questionObject = new QuestionObject();
            questionObject.setQuestionItemObjects(questionItemObjects);
            questionObject.setTextContent(questionMySqlVm.getQtitle());
            QuestionEditRequestVM questionEditRequestVM = modelMapper.map(question, QuestionEditRequestVM.class);
            List<QuestionMySqlVm> questionMySqlVmList = JsonUtil.toJsonListObject(question.getTextContent(),QuestionMySqlVm.class);
            List<String> content = new ArrayList<>();
            for(QuestionMySqlVm questionMySqlSelectVm : questionMySqlVmList){
                content.add(questionMySqlSelectVm.getQtitle());
            }
            String textContent = JsonUtil.toJsonStr(content);
            questionEditRequestVM.setTextContent(textContent);

            questionEditRequestVM.setItemsAndIndex(questionIndexList);
            if(question.getScore()!= null){
                questionEditRequestVM.setScore(ExamUtil.scoreToVM(question.getScore()));
            }
            questionEditRequestVM.setAnalyze(questionObject.getAnalyze());

            //题目项映射
            List<QuestionEditItemVM> editItems = questionObject.getQuestionItemObjects().stream().map(o -> {
                QuestionEditItemVM questionEditItemVM = modelMapper.map(o, QuestionEditItemVM.class);
                if (o.getScore() != null) {
                    questionEditItemVM.setScore(ExamUtil.scoreToVM(o.getScore()));
                }
                return questionEditItemVM;
            }).collect(Collectors.toList());

            QuestionIndex questionIndex = new QuestionIndex();
            questionIndex.setItems(editItems);
            questionIndex.setIndex(++index);

            questionIndexList.add(questionIndex);
            questionEditRequestVM.setItemsAndIndex(questionIndexList);
            if (question.getArticleContentId() != null) {
                Article article = articleService.selectById(question.getArticleContentId());
                questionEditRequestVM.setArticle(article.getArticleContent());
            }
            return questionEditRequestVM;
        }else if(question.getSubjectParentId()==1){
            List<QuestionIndex> questionIndexList = new ArrayList<>();


            QuestionEditRequestVM questionEditRequestVM = modelMapper.map(question, QuestionEditRequestVM.class);
//            QuestionMySqlVm questionMySqlVm =(QuestionMySqlVm) questionMySqlVms.get(0);
            List<QuestionMySqlVm> questionMySqlVmList = JsonUtil.toJsonListObject(question.getTextContent(),QuestionMySqlVm.class);
            List<String> content = new ArrayList<>();
            for(QuestionMySqlVm questionMySqlSelectVm : questionMySqlVmList){
                content.add(questionMySqlSelectVm.getQtitle());
            }
            String textContent = JsonUtil.toJsonStr(content);
            questionEditRequestVM.setTextContent(textContent);
            //            questionEditRequestVM.setTextContent(null);
            for(QuestionMySqlVm questionMySqlVm :questionMySqlVms){
                List<QuestionItemObject> questionItemObjects = new ArrayList<>();
                QuestionObject questionObject = new QuestionObject();
                List<QuestionMySqlSelectVm> questionItems = questionMySqlVm.getItem();
                if(questionMySqlVm.getItem() != null){
                    for (QuestionMySqlSelectVm questionMySqlSelectVm : questionItems) {
                        QuestionItemObject questionItemObject = modelMapper.map(questionMySqlSelectVm, QuestionItemObject.class);
                        questionItemObjects.add(questionItemObject);
                    }
                }
                questionObject.setQuestionItemObjects(questionItemObjects);
                String qtitle = questionMySqlVm.getQtitle();
                questionObject.setTextContent(qtitle);
                if(question.getScore()!= null){
                    questionEditRequestVM.setScore(ExamUtil.scoreToVM(question.getScore()));
                }
                questionEditRequestVM.setAnalyze(questionObject.getAnalyze());
                //题目项映射
                List<QuestionEditItemVM> editItems = questionObject.getQuestionItemObjects().stream().map(o -> {
                    QuestionEditItemVM questionEditItemVM = modelMapper.map(o, QuestionEditItemVM.class);
                    if (o.getScore() != null) {
                        questionEditItemVM.setScore(ExamUtil.scoreToVM(o.getScore()));
                    }
                    return questionEditItemVM;
                }).collect(Collectors.toList());
                QuestionIndex questionIndex = new QuestionIndex();
                questionIndex.setItems(editItems);
                questionIndex.setIndex(++index);
                questionIndexList.add(questionIndex);


            }
            if (question.getArticleContentId() != null) {
                Article article = articleService.selectById(question.getArticleContentId());
                questionEditRequestVM.setArticle(article.getArticleContent());
            }
            questionEditRequestVM.setItemsAndIndex(questionIndexList);
            return questionEditRequestVM;
        }

        return null;
    }
    @Override
    public List<ExamPaper> selectList(ExamPaper examPaper) {
        return examPaperMapper.selectList(examPaper);
    }
    @Override
    public ExamPaper getExamPaperById(Integer id) {
        return examPaperMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<ExamPaperVM> pagevm(ExamPaperPageRequestVM requestVM) {
        PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize());
        List<ExamPaper> examPapers = examPaperMapper.page(requestVM);
        PageInfo<ExamPaper> pageInfoa = new PageInfo<>(examPapers);
        List<ExamPaperVM> examPaperVms = examPapers.stream().map(examPaper -> {
            ExamPaperVM examPaperVm = modelMapper.map(examPaper, ExamPaperVM.class);
            DataDictionary dataDictionary = dataDictionaryMapper.selectByPrimaryKey(examPaper.getPaperType());
            examPaperVm.setPaperTypeName(dataDictionary.getCategoryName());
            DataDictionary dataDictionary1 = dataDictionaryMapper.selectByPrimaryKey(examPaper.getSubjectId());
            examPaperVm.setSubjectName(dataDictionary1.getCategoryName());
            return examPaperVm;
        }).collect(Collectors.toList());
        PageInfo<ExamPaperVM> pageInfo = new PageInfo<>(examPaperVms);
        pageInfo.setTotal(pageInfoa.getTotal());
        pageInfo.setPageNum(requestVM.getPageIndex());
        return pageInfo;
    }

    @Override
    public int deletePaper(ExamPaper examPaper) {
        int textContentId = examPaper.getFrameTextContentId();
        textContentService.deleteById(textContentId);
        return examPaperMapper.deleteByPrimaryKey(examPaper.getPaperId());
    }
    @Override
    public long getExamPaperCount() {

        return examPaperMapper.selectAllCount();
    }

    @Override
    public ExamPaperEditRequestVM ExamPaperAddAi(ExampaperAddAIVM exampaperAddAIVM) {
        ExamPaperEditRequestVM examPaperEditRequestVM = new ExamPaperEditRequestVM();
        if(exampaperAddAIVM != null){
            //获取科目Id
            Integer subjectId = exampaperAddAIVM.getSubjectId();
            //修改titleItem部分
            List<ExamPaperTitleItemVM> titleItems = exampaperAddAIVM.getTitleItems();
            for(ExamPaperTitleItemVM examPaperTitleItemVM : titleItems){
                if(examPaperTitleItemVM.getQuestionItems() != null){
                    List<QuestionEditRequestVM> questionItems = examPaperTitleItemVM.getQuestionItems();
                    for(QuestionEditRequestVM questionEditRequestVM : questionItems){
                        QuestionVMUpdate q1 = new QuestionVMUpdate();
//                        questionService.insertQuestion(q1);
                        q1.setQuestionTypeId(questionEditRequestVM.getQuestionType());
                        q1.setSubjectParentId(subjectId);
                        List<String> correctArray =questionEditRequestVM.getCorrectArray();
                        //拼接正确答案
                        StringBuilder coorectBuilder = new StringBuilder();
                        for (int i = 0; i < correctArray.size(); i++) {
                            coorectBuilder.append(correctArray.get(i));
                            if (i < correctArray.size() - 1) {
                                coorectBuilder.append(',');
                            }
                        }
                        String coorect = coorectBuilder.toString();
                        q1.setCorrect(coorect);
                        QuestionMySqlVm qm = new QuestionMySqlVm();
                        String textContent = questionEditRequestVM.getTextContent();
                        qm.setQtitle(textContent.substring(2, textContent.length() - 2));
                        List<QuestionMySqlSelectVm> items = new ArrayList<>();
                        for (QuestionIndex questionIndex : questionEditRequestVM.getItemsAndIndex()){
                            questionIndex.getItems().forEach(questionEditItemVM -> {
                                QuestionMySqlSelectVm qms = new QuestionMySqlSelectVm();
                                qms.setPrefix(questionEditItemVM.getPrefix());
                                qms.setContent(questionEditItemVM.getContent());
                                items.add(qms);
                            });
                        }

                        qm.setItem(items);
                        List<QuestionMySqlVm> list = new ArrayList<>();
                        list.add(qm);
                        q1.setTextContent(JsonUtil.toJsonStr(list));
                        //设置题目初始状态 默认为1
                        q1.setStatus(1);
                        //给分数设置的默认值
                        q1.setScore(20);
                        //根据题型进行判断给对应的分数
                        //if判断
                        /*if (q1.getQuestionTypeId()!=null){
                            //阅读理解
                            if (q1.getQuestionTypeId() == 20){
                                q1.setScore(10);
                            }
                            //翻译
                            if (q1.getQuestionTypeId() == 21){
                                q1.setScore(20);
                            }
                            //完型填空
                            if (q1.getQuestionTypeId() == 22){
                                q1.setScore(20);
                            }
                            //小作文
                            if (q1.getQuestionTypeId() == 23){
                                q1.setScore(20);
                            }
                            //大作文
                            if (q1.getQuestionTypeId() == 24){
                                q1.setScore(20);
                            }
                            //英语选择题
                            if (q1.getQuestionTypeId() == 25){
                                q1.setScore(20);
                            }
                            //英语长短句
                            if (q1.getQuestionTypeId() == 32){
                                q1.setScore(20);
                            }
                            //政治单项选择题
                            if (q1.getQuestionTypeId() == 26){
                                q1.setScore(20);
                            }
                            //政治多项选择题
                            if (q1.getQuestionTypeId() == 27){
                                q1.setScore(20);
                            }
                            //分析题
                            if (questionEditRequestVM.getQuestionType() == 28){
                                q1.setScore(20);
                            }
                            //数学选择题
                            if (questionEditRequestVM.getQuestionType() == 29){
                                q1.setScore(20);
                            }
                            //数学填空题
                            if (questionEditRequestVM.getQuestionType() == 30){
                                q1.setScore(20);
                            }
                            //数学简单题
                            if (questionEditRequestVM.getQuestionType() == 31){
                                q1.setScore(20);
                            }
                        }*/
                        //swithc判断
                        switch (q1.getQuestionTypeId()) {
                            case 20: // 阅读理解
                                q1.setScore(10);
                                break;
                            case 21: // 翻译
                                q1.setScore(20);
                                break;
                            case 22: // 完型填空
                                q1.setScore(20);
                                break;
                            case 23: // 小作文
                                q1.setScore(20);
                                break;
                            case 24: // 大作文
                                q1.setScore(20);
                                break;
                            case 25: // 英语选择题
                                q1.setScore(20);
                                break;
                            case 32: // 英语长短句
                                q1.setScore(20);
                                break;
                            case 26: // 政治单项选择题
                                q1.setScore(20);
                                break;
                            case 27: // 政治多项选择题
                                q1.setScore(20);
                                break;
                            case 28: // 分析题
                                q1.setScore(20);
                                break;
                            case 29: // 数学选择题
                                q1.setScore(20);
                                break;
                            case 30: // 数学填空题
                                q1.setScore(20);
                                break;
                            case 31: // 数学简单题
                                q1.setScore(20);
                                break;
                            default:
                                // 如果需要处理其他题型，可以在这里添加逻辑
                                q1.setScore(0); // 默认分数为0或其他默认值
                                break;
                        }

                        q1.setCreateUserId(0);
                        questionService.insertQuestion(q1);
                        questionEditRequestVM.setId(q1.getId());
                    }
                }
            }
            examPaperEditRequestVM.setName(exampaperAddAIVM.getName());
            examPaperEditRequestVM.setSubjectId(exampaperAddAIVM.getSubjectId());
            examPaperEditRequestVM.setPaperType(34);
            examPaperEditRequestVM.setTitleItems(titleItems);
        }
        return examPaperEditRequestVM;
    }

}
